package com.java.socket;

import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class TcpClient {

	@Test
	public void client() throws IOException, InterruptedException {
		Socket socket = new Socket("127.0.0.1",5000);

		OutputStream out = socket.getOutputStream();
		out.write("如果上天知我心诚，就让石头也发芽吧。".getBytes());
		InputStream in = socket.getInputStream();
		byte[] bytes = new byte[200];
		int length = 0;
		while(-1 != (length = in.read(bytes,0,200))){
			String str = new String(bytes,0,length);
			System.out.print(str);
		}
		out.close();
		in.close();
		socket.close();
	}
}
